<%@page contentType="text/html; charset=utf-8"%>
<%@page import="dao.UserDao"%>
<%@page import="dao.DaoFactory"%>
<%@page import="entity.User"%>
<%@page import="dao.PhotoDao"%>
<%@page import="java.util.List"%>
<%@page import="entity.Photo"%>
<html>
	<head>
		<title>update Emp</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<link rel="stylesheet" type="text/css" href="css/style.css" />
	</head>
	<body>
		<div id="wrap">
			<div id="top_content">
				<div id="header">
					<div id="rightheader">
						<p>
							2009/11/20
							<br />
						</p>
					</div>
					<div id="topheader">
						<h1 id="title">
							<a href="#">Main</a>
						</h1>
					</div>
					<div id="navigation">
					</div>
				</div>

				<div id="content">
					<p id="whereami">
					</p>
					<h1>
						User Detail:
					</h1>
					<table class="table">
						<tr>
							<td>
								姓名
							</td>
							<td>
								电话
							</td>
						</tr>
						<tr>

							<%
								UserDao dao = DaoFactory.getInstance(UserDao.class);
								int id = Integer.parseInt(request.getParameter("id"));
								User u = dao.findById(id);
							%>
							<td>
								<%=u.getName()%>
							</td>
							<td>
								<%=u.getPhone()%>
							</td>
						</tr>
					</table>
					<%
						Integer loginId = (Integer) session.getAttribute("id");
						if (loginId!=null&&loginId == id) {
					%>
					<h1>
						Load Photo:
					</h1>

					<form action="uploadPhoto.do?id=<%=u.getId()%>" method="post"
						enctype="multipart/form-data">
						Upload File Name:
						<input type="file" name="photo" />
						<input type="submit" value="confirm" />
					</form>
					<%
						}
						if (loginId != null) {
							PhotoDao photoDao = DaoFactory.getInstance(PhotoDao.class);
							List<Photo> photos = photoDao.findByUserId(id);
					%>
					<h1>
						view photo:
					</h1>
					<table>
						<%
							if (photos != null && photos.size() > 0) {
									for (int i = 0; i < photos.size(); i++) {
										Photo photo=photos.get(i);
						%>
						<tr>
							<td>
								<img src="photos/photo_<%=u.getId()%>/<%=photo.getName() %>" width="300" />
							</td>
						</tr>
						<%
								}
							}
						%>

					</table>
					<%
						}
					%>



				</div>
				<a href="userList.jsp" style="font-size: 30">return</a>
			</div>
			<div id="footer">
				<div id="footer_bg">
					ABC@126.com
				</div>
			</div>
		</div>
	</body>
</html>
